<template>
  <el-dialog v-model="visible" title="平台回复" :close-on-click-modal="false">
    <el-form
      ref="dataFormRef"
      :model="dataForm"
      :rules="dataRule"
      label-width="120px"
      @keyup.enter="onSubmit()"
    >
      <el-form-item label="用户账号" prop="userName">
        <el-input v-model="dataForm.userName" placeholder="用户账号" disabled/>
      </el-form-item>

      <el-form-item label="反馈类型" prop="type">
        <el-radio-group v-model="dataForm.type" disabled>
          <el-radio :label="0"> 投诉 </el-radio>
          <el-radio :label="1"> 建议 </el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="反馈内容" prop="content">
        <el-input v-model="dataForm.content" placeholder="反馈内容" type="textarea"  :rows="2" disabled/>
      </el-form-item>

      <el-form-item label="反馈图片" prop="imgs">
        <el-image v-for="item in (dataForm.imgs || '').split(',')" style="width: 50px; height: 50px" :src="resourcesUrl+item" fit="cover" :preview-src-list="(dataForm.imgs || '').split(',').map(function (num) {return resourcesUrl + num;})"  />
      </el-form-item>

      <el-form-item label="平台回复" prop="platformReply">
        <el-input v-model="dataForm.platformReply" placeholder="平台回复" type="textarea"  :rows="3" />
      </el-form-item>
    </el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="visible = false">取消</el-button>
        <el-button type="primary" @click="onSubmit()">确定</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script setup>
const emit = defineEmits(["refreshDataList"]);
const resourcesUrl = import.meta.env.VITE_APP_RESOURCES_URL

const page = reactive({
  total: 0, // 总页数
  currentPage: 1, // 当前页数
  pageSize: 10, // 每页显示多少条
});

const dataForm = ref({
  id: "",
  uid: "",
  userName:"",
  type: "",
  content: "",
  imgs: "",
  platformReply:"",
  state:0,
});

const dataRule = {
  platformReply: [
    //{ required: true, message: "添加数量不能为空", trigger: "change" },
    //Vue中自定义校验
    {
      validator: (rule, value, callback) => {
        if ((dataForm.value.platformReply == null ||dataForm.value.platformReply == '')) {
          callback(new Error("平台回复不能为空"));
        } else {
          callback();
        }
      },
      trigger: "blur",
    },
  ],
};
const visible = ref(false);
const dataFormRef = ref(null);
const init = (row) => {
  visible.value = true;
  dataForm.value = row || {};
  nextTick(() => {
    //在 el-form 中的字段,调用resetFields方法后会将当前值,覆盖为第一次打开el-form时各字段的值
    //dataFormRef.value?.resetFields();
  });
};
defineExpose({ init });



const onSubmit = Debounce(() => {
  dataFormRef.value?.validate((valid) => {
    if (valid) {
      http({
        url: http.adornUrl("/admin/complaintSuggestions"),
        method: "put",
        data: http.adornData({
          id: dataForm.value.id || undefined,
          platformReply: dataForm.value.platformReply,
          state: 1
        }),
      }).then(() => {
        ElMessage({
          message: "操作成功",
          type: "success",
          duration: 1500,
          onClose: () => {
            visible.value = false;
            emit("refreshDataList", page);
          },
        });
      });
    }
  });
});





</script>

<style scoped lang="scss">

</style>

<style scoped>

</style>
